var t = require("../../utils/config.js");

Page({
    data: {
        userInfo: {},
        isShowModal: !1,
        modalTitle: "",
        modalPlaceHolder: "",
        editInputValue: "",
        modalDefaultValue: "",
        educationList: [ "其他", "博士", "硕士", "本科", "大专", "中专", "高中", "初中", "小学" ],
        jobIntentionList: []
    },
    onLoad: function(t) {
        this.loadDataSource(), this.getJobIntention();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    loadDataSource: function() {
        var e = this;
        wx.showLoading({
            mask: !0
        }), wx.getStorage({
            key: "userId",
            success: function(a) {
                wx.request({
                    url: t.urlList.API_USER_GET_PERSONAL_INFO,
                    method: "GET",
                    data: {
                        userId: a.data
                    },
                    header: {
                        contentType: "application/json"
                    },
                    success: function(t) {
                        wx.hideLoading(), e.setData({
                            userInfo: t.data.data
                        });
                    }
                });
            }
        });
    },
    updateUserInfo: function(e) {
        var a = this, n = wx.getStorageSync("userId");
        e.userId = n, wx.showLoading({
            mask: !0
        }), wx.request({
            url: t.urlList.API_USER_UPDATE_PERSONAL_INFO,
            method: "POST",
            data: e,
            header: {
                contentType: "application/json"
            },
            success: function(t) {
                wx.hideLoading(), 200 == t.data.status ? a.loadDataSource() : wx.showToast({
                    title: t.data.message,
                    icon: "none"
                });
            }
        });
    },
    cancel: function() {
        this.setData({
            isShowModal: !1
        });
    },
    confirm: function() {
        var t = this;
        "年龄" == t.data.modalTitle ? t.updateUserInfo({
            age: 30
        }) : "户籍详细地址" == t.data.modalTitle ? t.updateUserInfo({
            registerAddress: t.data.editInputValue
        }) : "户籍详细地址" == t.data.modalTitle ? t.updateUserInfo({
            registerAddress: t.data.editInputValue
        }) : "专业" == t.data.modalTitle ? t.updateUserInfo({
            major: t.data.editInputValue
        }) : "社保账号" == t.data.modalTitle ? t.updateUserInfo({
            socialNumber: t.data.editInputValue
        }) : "部门" == t.data.modalTitle ? t.updateUserInfo({
            department: t.data.editInputValue
        }) : "求职意向" == t.data.modalTitle && t.updateUserInfo({
            jobIntention: t.data.editInputValue
        }), t.setData({
            isShowModal: !1
        });
    },
    getInput: function(t) {
        this.setData({
            editInputValue: t.detail.value
        });
    },
    editInput: function(t) {
        t.currentTarget.dataset.title ? this.setData({
            modalTitle: t.currentTarget.dataset.title,
            modalPlaceHolder: t.currentTarget.dataset.message,
            modalDefaultValue: t.currentTarget.dataset.value,
            isShowModal: !0,
            editInputValue: ""
        }) : wx.showToast({
            title: "请通过实名认证修改",
            icon: "none"
        });
    },
    selectGender: function() {
        var t = this;
        wx.showActionSheet({
            itemList: [ "男", "女" ],
            success: function(e) {
                t.updateUserInfo({
                    gender: 0 == e.tapIndex ? 1 : 2
                });
            }
        });
    },
    selectedEducation: function(t) {
        var e = this;
        e.updateUserInfo({
            education: e.data.educationList[t.detail.value]
        });
    },
    selectedJobIntention: function(t) {
        var e = this;
        e.updateUserInfo({
            jobIntention: e.data.jobIntentionList[t.detail.value]
        });
    },
    selectedRegister: function(t) {
        this.updateUserInfo({
            registerProvince: t.detail.value[0],
            registerCity: t.detail.value[1],
            registerArea: t.detail.value[2]
        });
    },
    selectedLive: function(t) {
        this.updateUserInfo({
            liveProvince: t.detail.value[0],
            liveCity: t.detail.value[1],
            liveArea: t.detail.value[2]
        });
    },
    selectedSocial: function(t) {
        this.updateUserInfo({
            socialProvince: t.detail.value[0],
            socialCity: t.detail.value[1],
            socialArea: t.detail.value[2]
        });
    },
    goToEditBank: function() {
        wx.navigateTo({
            url: "editBank"
        });
    },
    getJobIntention: function() {
        var e = this;
        wx.request({
            url: t.urlList.API_USER_GET_JOB_INTENTION,
            method: "GET",
            success: function(t) {
                200 == t.data.status && e.setData({
                    jobIntentionList: t.data.data
                });
            }
        });
    }
});